5. Scripting Speed Download



 

5.1 Introduction

Starting with Speed Download version 0.9b, you can use Applescript to automate tasks. Using Applescript you can alter many settings, start downloads, monitor their progression and more. There are many potential uses for this. You could write a script that would download a file and then power down the computer. You could then have your computer turn on late at night, when phone calls are cheaper and people won't be trying to call you if you are a modem user or simply because the Internet is less busy at that time and download files by placing the script in your startup items folder.
5.2 Command Reference
This is a complete reference of all the Applescript commands that Speed Download 0.9b supports

DownloadURL:

Parameters: a list of strings, each a URL of a file to download.

Returns: a list of integers. Each of the integers is known as a DownloadID, it is a small negative integer that you can use to refer to the download (s) you have started. A DownloadID is unique for a given session.

Description: DownloadURL starts the downloads of the URLs that you specify. You should take care to preserve the DownloadIDs returned as you will need them if you to make commands that apply to a specific download. Before running a script that makes use of this command you should set a default folder for Speed Download (see section 4. If you do not then Speed Download will ask where to save the downloaded file which will cause the script to time-out.


CancelDownload:

Parameters: a long integer, the DownloadID for an ongoing download you wish to cancel

Returns: an integer. See description for interpretation of this code

Description: Cancels a previously started download.

Possible return values:

0 : The download was successfully cancelled
-4: The downloadID you supplied was invalid : the corresponding download does not exist or has finished.
GetDownloadStatus:
Parameters:  long integer, the DownloadID for the download whose status you wish to know

Returns: a double integer. See description for interpretation of this number

Description: Gets the status of a download. If the return value is positive, then the download has started and the value returned represents the number of bytes that have been received so far. If not,  the download is in a state identified by one of the following (negative)  constants:

-1 : the download has been initiated but data transfer has not yet started
-2 : the download has completed successfully
-3 : the download completed because an error occurred
-5 : the download was cancelled
-4 : the DownloadID you supplied did not reference a download
GetDownloadSize:
Parameters:  long integer, the DownloadID for the download whose size you wish to know

Returns: a double integer. See description for interpretation of this number

Description: Fetches the size in bytes of a file being downloaded. If you call this too early, before the size of the file has been determined the file size returned will be zero. If the information could not be retrieved, a negative error code is returned. The downloadID must reference a download that is still being processed. If the download has finished, kBadDownloadID will be returned.

Possible return values:

-4 : the DownloadID you supplied did not reference an ongoing download
GetStatus:
Parameters: none

Returns: a small integer

Description: GetStatus returns the number of downloads that are currently active
 

SetNumberOfPorts:
Parameters: an integer, the new number of ports

Returns: nothing

Description: Sets the number of ports to be used for future downloads to the value you supply
 

SetBufferSize:
Parameters: a small integer, the new buffer size per connection, in kilobytes

Returns: nothing

Description: Sets the size in kilobytes of the buffer that is used for each connection
 

SetPassiveMode:
Parameters: a boolean

Returns: nothing

Description: if you pass true to SetPassiveMode, future ftp downloads will use passive ftp, if you pass false, they will not.
 

5.3 Example Script
 
The following script launches Speed Download if necessary sets the buffer size to 32 kb, tells speed download to download a file, waits till the download to finish before quitting Speed Download.

tell application "Speed Download"

activate
SetBufferSize (32)
SetNumberOfPorts (4)
DownloadURL ("http://simplemacs.multimania.com/MacMailPurger2.0.hqx")
set downloadID to number 1 of result --store the downloadID
set finished to false
repeat until finished --loop until download finishes or an error occurs
set status to GetDownloadStatus (downloadID) --get the status of the download
if ((status < 0) and (status is not -1)) then
        set finished to true
end if
end repeat
quit --quit Speed Download
end tell

Note that I am by no means an Applescript expert, this script is certainly perfectible

If you write any useful scripts, feel free to mail them to me and I may include them with future versions of Speed Download or put them up on my web site
 



[Table of contents] [Previous Page] [Next Page]

Copyright © 2000 Frederick Cheung. All rights reserved